package com.safe.ocs.controls;

import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.safe.ocs.beans.Blogin;
import com.safe.ocs.forms.LoginForm;
import com.safe.ocs.services.UserLogin;

public class Login extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {	
		LoginForm lform = (LoginForm) form;
		HttpSession session = request.getSession();
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		String userName = lform.getTxt_username();
		String password = lform.getTxt_password();
		Blogin userInfo = new UserLogin().certify(userName, password);
		if(userInfo!=null){
			session.setAttribute("userinfo", userInfo);
//			out.println("{success:true,msg:'登录成功！'}");	
		}else
			out.println("{success:false,msg:'用户名或密码错误，请重新登录！'}");
		out.flush();
		return null;
	}
	

}
